import { _decorator, Component, director, Node } from 'cc';
import { nodePool } from '../utils/nodePool';
import { gameConfig } from '../data/gameConfig';
import { emits, resPath } from '../data/enums';
const { ccclass, property } = _decorator;

@ccclass('game')
export class game extends Component {


    protected onLoad() {
        director.on(emits.gameCheck, this.check, this);
        director.on(emits.gamePause, this.showPauseUI, this)
        nodePool.ins.getPoolNode("top", this.node);
        gameConfig.isGame = 1;
        gameConfig.step = 0;
    }
    showPauseUI() {
        //audioTool.ins.playSound("btn")
        nodePool._ins.getPoolNode("pause", this.node);
    }
    //判断游戏进度
    check() {
        let isOver = true;
        //判断是否胜利
        gameConfig.redPoints.forEach(redPosition => {
            if (gameConfig.currentLevel[redPosition[0]][redPosition[1]] != 1)
                isOver = false;
            console.log("游戏继续")
        });
        if (isOver) {
            console.log("游戏胜利");
            nodePool.ins.getPoolNode("winView", this.node);
        }
    }
    protected onDestroy(): void {
        director.off(emits.gameCheck, this.check, this);
        director.off(emits.gamePause, this.showPauseUI, this)
        gameConfig.isGame = 1;
        gameConfig.step = 0;
    }
    reStart() {
        director.loadScene("game");
    }
}


